package com.ny.service;

import com.ny.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailService {
    @Autowired
    private JavaMailSender mailSender;
    @Value("${spring.mail.username}")
    private String fromEmail;

    public void sendEmail(String toEmail, String code) {
        // 创建邮件对象
        SimpleMailMessage message = new SimpleMailMessage();
        // 设置邮件发送方
        message.setFrom(fromEmail);
        // 设置邮件接收方
        message.setTo(toEmail);
        // 设置邮件主题
        message.setSubject("重置密码验证码");
        // 设置邮件内容
        message.setText("验证码为："+code);
        // 发送邮件
        mailSender.send(message);
    }

    public String getCode() {
        int code = (int)(Math.random()*9000+1000);
        return String.valueOf(code);
    }
    // 给QQ邮箱发送验证码




}
